<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.Enumeration,java.util.ArrayList,java.util.HashMap,java.util.HashSet" %>
<%@ page import="cn.edu.nju.ws.aquila.query.Relation,cn.edu.nju.ws.aquila.user.User" %>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Relation</title>
<link rel="stylesheet" type="text/css" href="css/layout.css" />
<link rel="stylesheet" type="text/css" href="css/main_relation.css" />
<link rel="stylesheet" type="text/css" href="css/smoothness/jquery-ui-1.8.16.custom.css" />
<script type="text/javascript" src="script/jquery.js"></script>
<script type="text/javascript" src="script/main_relation.js"></script>
<script type="text/javascript" src="script/jquery-ui-1.8.16.custom.min.js"></script>
</head>
<body>
		<div id="wrapper">
			<div id="top">
				<div id="user">
					welcome, <span id="userName"><%=session.getAttribute("user")%></span>
				</div>
				<div id="navigation-bar"><a href='main_datasource.jsp' class="nav-title">Datasource</a><a href='main_relation.jsp' class="nav-title">Relation</a><a href='main_query.jsp' class="nav-title">Query</a><a href='logout' class="nav-title">Logout</a></div>
				<div class="mspacing"></div>
				<div id="mbutton-bar">
					<div class="float-button"><a href="#" id="op_importRelation">Import an new relation</a></div>
					<div class="float-button"><a href="construct_relation.jsp">Construct a new relation</a></div>
					<br class="clear" />
				</div>
			</div>
			<div id="main">
				<div id="left">
					<h3>My relations</h3>
					<ul>
					 <%
						String user = (String) session.getAttribute("user");
						ArrayList<Integer> constructedRelations = Relation.getRelationsOfAuthor(user);
						for (int relationId : constructedRelations) {
							String name  = Relation.getName(relationId);
							String alias = null;
							alias = Relation.getRelationAliasByUser(user,relationId) ;
							if(alias!=null)
								name = alias;
					  %>
					 <li><p><a href="#" class="relationLink" datatypeid="<%=relationId%>"><%=name%></a></p><div class="tag-helper"><img src="icons/edit_view.png" alt="edit tags" width="10" height="10"/></div></li>
					 <% 
					    }
					 %>
					</ul>			
					<h3>Imported relations</h3>
					<ul id="importedrelationList">
					  <%
					    ArrayList<Integer> importedRelations =  Relation.getImportedRelationIdByUser(user);
					    for(int relationId:importedRelations){
					    	String name  = Relation.getName(relationId);
							String alias = null;
							alias = Relation.getRelationAliasByUser(user,relationId) ;
							if(alias!=null)
								name = alias;
					  %>
					 <li><p><a href="#" class="relationLink" datatypeid="<%=relationId%>"><%=name%></a></p><div class="tag-helper"><img src="icons/edit_view.png" alt="edit tags" width="10" height="10"/></div></li>
					 <% 
					    }
					 %>						
					</ul>
				</div>
				<div id="right"></div>
				<br class="clear"/>
			</div>
		</div>
		<div class="hidden">
			<div id="tag-display">
				<a href="#" class="tag-closer">x</a>
				<h3>Rename</h3>
				<p>name:</p><input id="newname" type="text"/>
				<input type="submit" value="ok" id="renameButton"/>
			</div>
		</div>
		<div id="import-relation" title="Import a new relation">
					<div class="searchBar">
					<input type="text" id="relation_searchBar" /><input type="button" name="search" value="search" id="searchButton"/>
					  </div>
					  <div class="searchResult">
						<ul id="relationSearchResult"></ul>
					  </div>
		</div>
	<div id="footer"></div>
</body>
</html>